﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using Soussous.DAO;
using Soussous.Business;
using Soussous.DAO.Impl;


namespace Soussous.Template
{
    public partial class historical : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (HttpContext.Current.Session["user"] == null)
            {
                Response.Redirect("unauthorizedAccess.aspx");
            }


            User theUser = (User) HttpContext.Current.Session["user"];
            var list = OperationDAO.getInstance().historical(theUser.Id);

            
            foreach (Operation ope in list)
            {
                HtmlTableRow myTableRow = new HtmlTableRow();
                HtmlTableCell cellule1 = new HtmlTableCell();
                HtmlTableCell cellule2 = new HtmlTableCell();
                HtmlTableCell cellule3 = new HtmlTableCell();
                HtmlTableCell cellule4 = new HtmlTableCell();
                HtmlTableCell cellule5 = new HtmlTableCell();
                cellule1.InnerHtml = ope.note.Date.ToString("dd-MM-yy");
                if (ope.User_to == theUser.Id)
                {
                    cellule2.InnerHtml = ope.un_user_from.Firstname.ToString();
                    cellule3.InnerHtml = "He paid me";
                }
                else
                {
                    cellule2.InnerHtml = ope.un_user_to.Firstname.ToString();
                    cellule3.InnerHtml = "I paid ";
                }
                cellule4.InnerHtml = ope.Amount.ToString();
                cellule5.InnerHtml = ope.note.Description.ToString();
                myTableRow.Cells.Add(cellule1);
                myTableRow.Cells.Add(cellule2);
                myTableRow.Cells.Add(cellule3);
                myTableRow.Cells.Add(cellule4);
                myTableRow.Cells.Add(cellule5);
                listing.Rows.Add(myTableRow);

            }
            
          
        }
    }
}
